Simplified Windows Azure SDK

Simple Azure provides a wrapper function to Windows Azure SDK for Python so that many steps can be reduced and hidden with default configurations.

This tutorial provide a basic step to deploy a default virtual machine using Simple Azure.

Import Simple Azure package


In [1]:
from simpleazure import SimpleAzure as saz

Load certificates

Simple Azure loads a default setting from a profile. $HOME/.azure directory keeps a certificate and a configuration for azure-cli so Simple Azure refers the directory to get access information such as a .cer file and a subscription id.


In [2]:
azure = saz()
azure.asm.get_config()

Note.
get_config() includes cert.getSubscription() and cert.getManagementCertFile().
In IPython Notebook, adding ? or ?? to the end of a function name provides docstrings and source code on a hidden cell like below.


In [6]:
azure.asm.get_config?

Create a default virtual machine

create_vm() requests to deploy a virtual machine and returns a request id.


In [ ]:
result = azure.asm.create_vm()

Check status of the deployment

Deploying a virtual machine may take several minutes to be completed and you can check the status with the request id.


In [7]:
vars(azure.asm.get_status())


Out[7]:
{'error': None, 'http_status_code': u'200', 'id': u'', 'status': u'Succeeded'}

If the status above indicates 'Succeeded', your request has been successfully accepted and Window Azure is working on deploying the virtual machine.

Detail information of the deployment

You can check the status of the deployed virtual machine and get a hostname of the VM and so on. You can check other information below.


In [6]:
vars(azure.asm.get_deployment())


Out[6]:
{'configuration': u'<ServiceConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">\r\n  <Role name="myvm-20735">\r\n    <Instances count="1" />\r\n  </Role>\r\n</ServiceConfiguration>',
 'created_time': u'2013-07-22T16:10:18Z',
 'deployment_slot': u'Production',
 'extended_properties': {},
 'input_endpoint_list': None,
 'label': u'bXl2bS0yMDczNQ==',
 'last_modified_time': u'',
 'locked': False,
 'name': u'myvm-20735',
 'persistent_vm_downtime_info': None,
 'private_id': u'17071ce8bea345cf9451835c8510c84a',
 'role_instance_list': <azure.servicemanagement.RoleInstanceList at 0x333b5d0>,
 'role_list': <azure.servicemanagement.RoleList at 0x333b610>,
 'rollback_allowed': False,
 'sdk_version': u'',
 'status': u'Running',
 'upgrade_domain_count': u'1',
 'upgrade_status': None,
 'url': u'http://myvm-20735.cloudapp.net/'}

If you see 'status' is Running, your virtual machine is ready to use. You can access to the machine via SSH.

Note.

azure.asm.create_vm() contains several sdk functions like as follows:

sms = ServiceManagementService(subscription_id, certificate_path)
sms.create_hosted_service(service_name=name, label=name, location=location)
linux_config = LinuxConfigurationSet(name, linux_user_id, linux_user_passwd, False)
linux_config.ssh.public_keys.public_keys.append(publickey)
linux_config.ssh.key_pairs.key_pairs.append(keypair)
network = ConfigurationSet()
network.configuration_set_type = 'NetworkConfiguration'
network.input_endpoints.input_endpoints.append(ConfigurationSetInputEndpoint('ssh', 'tcp', '22', '22'))
cert_res = sms.add_service_certificate(service_name=name, data=cert_data, certificate_format=cert_format, password=cert_password)
result = sms.create_virtual_machine_deployment(service_name=name, deployment_name=name, deployment_slot='production', label=name, role_name=name, system_config=linux_config, os_virtual_hard_disk=os_hd, network_config=network, role_size='Small')

If you want to see the current implementation,
azure.asm.create_vm?? below will diplay the source code of the function in IPython Notebook.


In [8]:
azure.asm.create_vm??

Multiple deployment

create_cluster() function helps to deploy several machines at once. You need to simply specify the number of clusters as a parameter.


In [8]:
azure.asm.create_cluster(num=4)

There are other functions to utilize virtual machine images from the communnity (VM DEPOT) and communicate master and engine node(s) of clusters.
Other tutorials will explain how to use the other functions.